<?php


require_once '../config.php';
require_once '../functions.php';

$substance = book_fetch_all("select 
list.title,
options.option_isbn
from options
inner join list on list.list_isbn = options.option_isbn");


function add()
{
    $description = $_POST['description'];
    $authors = $_POST['authors'];
    $link = $_POST['link'];

    $rows = book_execute("insert into options (id,description,authors,link) values (null,'{$description}','{$authors}','{$link}')");
     
    $GLOBALS['success'] = $rows > 0;
    $GLOBALS['success'] = $rows <= 0 ? '更新成功！':'更新失败';
}

if (empty($_GET['isbn'])) {
    if($_SERVER['REQUEST_METHOD']==='POST'){
        add();
    }
}


?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Users &laquo; Admin</title>
  <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <script src="/static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
   

    <div class="container-fluid">
      <div class="page-title">
        <h1>内容修改</h1>
      </div>
      <?php if (isset($message)): ?>
     <?php if ($success):?>
              <!-- 有错误信息时展示 -->
      <div class="alert alert-success">
        <strong>成功！</strong><?php echo $message;?>
      </div>
    <?php else:?>
       <div class="alert alert-danger">
        <strong>错误！</strong><?php echo $message;?>
      </div>
     <?php endif ?>
     <?php endif ?>
      <form class="form-inline" action="<?php echo $_SERVER['PHP_SELF'];?>">
          <select name="isbn" class="form-control input-sm">
            <option value="all">所有分类</option>
            <?php foreach ($substance as $item): ?>
            <option value="<?php echo $item['option_isbn']; ?>"<?php echo isset($_GET['isbn']) && $_GET['isbn'] == $item['option_isbn'] ? ' selected' : '' ?>>
              <?php echo $item['title']; ?>
            </option>
            <?php endforeach ?>
          </select>
          <button class="btn btn-default btn-sm">筛选</button>
        </form>
       
        <div class="col-md-6">
    
            <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
            <div class="form-group">
             
            </div>
            <div class="form-group">
              <label for="description">描述</label>
              <textarea class="form-control" name="description" id="description" cols="30" rows="10" placeholder="描述"></textarea>
            </div>
            <div class="form-group">
              <label for="authors">作者</label>
              <textarea class="form-control" name="authors" id="authors" cols="30" rows="10" placeholder="作者"></textarea>
            </div>
            <div class="form-group">
              <label for="link">链接</label>
              <input class="form-control" type="text" name="link" id="link" value="">
            </div>
            <div class="form-group">
              <button class="btn btn-info" type="submit">添加</button>
              <a href="/admin/book.php" class="btn btn-info" type="submit">返回</a>
            </div>
          </form>
       
          
         
        </div>
    </div>
  </div>



  <script src="/static/assets/vendors/jquery/jquery.js"></script>
  <script src="/static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>
